home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / Technical.Notes / IIGS / TN.IIGS.039 < prev    next >
Encoding:
Text File  |  1989-08-21  |  6.3 KB  |  118 lines  |  [TEXT/pdos]

  1. Apple II
  2. Technical Notes
  3. _____________________________________________________________________________
  4.                                                   Developer Technical Support
  5.  
  6.  
  7. Apple IIGS
  8. #39:    Mega II Video Counters
  9.  
  10. Revised by:    Dave Lyons                                           July 1989
  11. Written by:    J. Rickard                                            May 1988
  12.  
  13. This Technical Note describes the Mega II video output registers, which your 
  14. applications can use to get information about where the beam is located on the 
  15. Apple IIGS display.
  16. Changes since November 1988:  Corrected description of when VBL begins 
  17. and simplified example code to read the scan line number.
  18. _____________________________________________________________________________
  19.  
  20. The Mega II controls video timing for the Apple IIGS with a 16-bit counter 
  21. split into a 7-bit horizontal and a 9-bit vertical part (Figure 1).  The 
  22. counter outputs are made available to programs running on the machine through 
  23. two addresses in the I/O space, $C02E for the vertical count and $C02F for the 
  24. horizontal count.  These outputs can be used by a program for finer control 
  25. over display update timing.
  26.  
  27.       _______________________________________________________________
  28.      |          Vertical Counter         |     Horizontal Counter    |
  29.      |___________________________________|___________________________|
  30.      | V5| V4| V3| V2| V1| V0| VC| VB| VA|HPE| H5| H4| H3| H2| H1| H0|
  31.      |_______________________________|___|___________________________|
  32.      |            $E0C02E            |             $E0C02F           |
  33.      |_______________________________________________________________|
  34.  
  35.                        Figure 1 - Mega II Video Counter
  36.  
  37. You can see that one bit of the nine-bit vertical counter is in location 
  38. $E0C02F with the seven bits of the horizontal counter.  Keep this location in 
  39. mind when reading the counters.
  40.  
  41. The seven-bit horizontal counter starts at $00 and counts from $40 to $7F (the 
  42. sequence is $00, $40, $41,...,$7E, $7F, $00, $40,...).  The active video time 
  43. consists of 40 one microsecond clock cycles starting with $58 and ending
  44. with $7F.  Since this count changes at 980 nanosecond intervals, it will
  45. probably be of little use to most programs.
  46.  
  47. The nine-bit vertical counter ranges from $FA through $1FF (250 through 511) 
  48. in NTSC mode (vertical line count of 262) and from $C8 through $1FF (200 
  49. through 511) in PAL video timing mode (vertical line count of 312).  Vertical 
  50. counter value $100 corresponds to scan line zero in NTSC mode.  The vertical 
  51. count changes at 63.7 microsecond intervals, giving a program time to respond
  52. to a specific count before it changes.  The vertical counter byte, at $E0C02E, 
  53. only changes half as often (at 127 microsecond intervals) since the lowest bit
  54. of the nine-bit counter is actually stored in the next byte (at $E0C02F).
  55.  
  56. The nine-bit counter consists of bits VA, VB, VC, V0, V1, V2, V3, V4 and V5.  
  57. Bits V0 through V5 can be read as a six-bit value.  If this value is between 0 
  58. and 23, it is the line on the text screen currently being updated.  Other 
  59. values indicate the vertical blanking cycle is occurring.  Bits VA through VC 
  60. can be read as a three-bit value (0-7) indicating which scan line of a text 
  61. character (characters are composed of eight lines) is currently being drawn.
  62.  
  63. The vertical counter can also be used to determine which scan line (0-191 for 
  64. most video modes, including high-resolution and double high-resolution, and
  65. 0-199 for super high-resolution) is being updated at any given moment.
  66.  
  67. Example
  68.  
  69. Suppose you want to repaint a portion of the super high-resolution screen that 
  70. will require more time than the vertical blanking period allows.  You will 
  71. have a tear in your animation when the screen's refresh cycle catches up with 
  72. your drawing.
  73.  
  74. One solution to this problem would be locating the approximate place the tear 
  75. occurs and starting your drawing when the system is scanning that line of 
  76. graphics.  Let's say you are painting an area that is about (for example) 100 
  77. pixels wide and 200 pixels tall in 320 mode, and that the tear will occur 
  78. somewhere around scan line 80.  To avoid the tear, you would wait until the 
  79. system is scanning line 80, then you would start redrawing at the top of the 
  80. screen.  This way, you should be finished drawing when the system is back to 
  81. scanning line 80 again and you will have flicker-free screen updating.
  82.  
  83. The tricky part is trying to determine just when the system is scanning any 
  84. given scan line.  One way to determine this is to examine the Mega II video 
  85. counter registers at $E0C02E (vertical) and $E0C02F (horizontal), described 
  86. above.  By using some simple arithmetic you can come up with the exact scan 
  87. line being updated.  The following piece of code computes the current scan 
  88. line number (assuming eight-bit native mode):
  89.  
  90.     lda    >$E0C02F
  91.     asl    A                    ;VA is now in the Carry flag
  92.     lda    >$E0C02E
  93.     rol    A                    ;roll Carry into bit 0
  94.  
  95. The result (in A) is the low byte of the vertical counter.  This value is 0 
  96. for the first scan line, 1 for the second scan line, etc.  Values $FA to $FF 
  97. are used twice, since you ignore the high byte of the vertical counter.  (The 
  98. six scan lines immediately above scan line 0 are numbered $0FA to $0FF, and 
  99. the six above those are $1FA to $1FF.)  The example code leaves the highest 
  100. bit of the vertical counter in the Carry flag, if you really want it.
  101.  
  102. Note that the VBL interrupts always trigger at scan line 192, even in Super 
  103. Hi-Res display mode, and that the $C019 soft switch indicates vertical 
  104. blanking is in effect starting at scan line 192.  Be careful polling for a 
  105. specific scan line number--if interrupts are enabled, it is conceivable that 
  106. the system will be busy processing an interrupt every time that scan line is 
  107. being scanned, so your program will hang forever waiting for it.
  108.  
  109. Setting a scan line interrupt is another way to determine when a particular 
  110. super high-resolution scan line is being drawn.  However, you must be careful 
  111. in turning scan line interrupts on and off so that you do not interfere with 
  112. the cursor in QuickDraw II (which uses scan line interrupts).
  113.  
  114.  
  115. Further Reference
  116. _____________________________________________________________________________
  117.     o    Apple IIGS Toolbox Reference, Volume 2
  118.     o    Apple IIGS Technical Note #40, VBL Signal